#ifndef __APP_DEVICE_H__
#define __APP_DEVICE_H__
#include "app_buffer.h"
#include "app_message.h"
#include <pthread.h>
#include <fcntl.h>
#include "app_mqtt.h"
#include "log/log.h"
#include "app_pool.h"
#include <unistd.h>
typedef struct
{
    char *file_name;
    int fd;
    buffer_t * up_buffer;
    buffer_t * down_buffer;
    pthread_t read_thread;    //读来自外部设备数据的线程
    int is_running; //读线程是否运行
    long long last_write_time;
    int (*post_read)(char *data, int len);
    int (*pre_write)(char *data, int len);

}device_t;

device_t * app_device_init(char * file_name);
/**
 * @brief 启动设备,本质上是启动读线程
 *
 * @return int 0 成功， -1 失败
 */
int app_device_start(void);
void app_device_destroy(void);
#endif /* __APP_DEVICE_H__ */
